package com.songshuai.webapi.crm.enumerations.error;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum CustomerError {



    ERROR_MOBILE_FORMAT(1,"手机号格式不正确"),
    ERROR_MOBILE_IS_EXITS(2,"手机号已存在");





    private int code;
    private String msg;

    CustomerError(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return CustomerError.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return CustomerError.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(CustomerError err : CustomerError.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
